/* @flow weak */

import React from 'react';
import {
  View,
  Text,
  StyleSheet,
} from 'react-native';

//KR-- redux 使用
//KR-0 安装 redux react-redux 并导入Redux必要头文件
import { Provider } from 'react-redux';
import { createStore } from 'redux';
//KR-1 reducers 逻辑处理中心
import AppReducer from '../../Redux/reducers/AppReducer.js'


// import RootTab from './AppRoot.js'
import RootStack from './AppRoot.js'
// import AppWithNavigationState from './AppRoot.js'
// import Tabnavigation from './AppRoot.js'


import {testAction,showTabBar,TabNavChanged} from '../../Redux/actions/AppActions.js'
// import {addTodo} from '../../Redux/actions/FindActions.js'

//KR-2创建 store 用来存储状态   创建AppReducer相关联的store
const store = createStore(AppReducer);


const AppProvider = () => {
  return (
  //KR-1 包裹一层Provider   之后进入被包裹控件内部 进行关联处理
  <Provider store={store}>
    <RootStack
      onNavigationStateChange={(prevState, newState, action) => {
        //这里能检测到 界面的跳转
        // console.log(newState.routes[0].index);
        // if (newState.index == 0) {
        //   var index = newState.routes[0].index;
        //   store.dispatch(TabNavChanged(index));
        // }
        
      }}
    />
    {/* <AppWithNavigationState></AppWithNavigationState> */}
  </Provider>
)};

export default AppProvider;

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
});
